FROM golang:1.13-alpine3.10 as build
RUN mkdir -p /go/kong-go \
    && pwd
COPY ./go-plugins/*  /go/kong-go/
RUN echo "https://mirrors.aliyun.com/alpine/v3.10/main/" >/etc/apk/repositories \
    && echo "https://mirrors.aliyun.com/alpine/v3.10/community/" >>/etc/apk/repositories \
	&& apk add --no-cache make automake gcc g++ \
	&& export GOPROXY=https://goproxy.io \
	&& export GO111MODULE=on \
    && cd /go/kong-go \
    && make

FROM alpine:3.10
LABEL maintainer="Kong Core Team <team-core@konghq.com>"

ENV KONG_VERSION 2.0.2
ENV KONG_SHA256 befe736bfde51e27ae51a0d6a827df44a1669099dea459d430aef0d570cc4db7

RUN adduser -S kong \
	&& mkdir -p "/usr/local/kong/go-plugins" \
	&& echo "https://mirrors.aliyun.com/alpine/v3.10/main/" >/etc/apk/repositories \
    && echo "https://mirrors.aliyun.com/alpine/v3.10/community/" >>/etc/apk/repositories \
	&& apk add --no-cache --virtual .build-deps curl wget tar ca-certificates \
	&& apk add --no-cache libgcc openssl pcre perl tzdata libcap su-exec zip \
	&& wget -O kong.tar.gz "https://bintray.com/kong/kong-alpine-tar/download_file?file_path=kong-$KONG_VERSION.amd64.apk.tar.gz" \
	&& echo "$KONG_SHA256 *kong.tar.gz" | sha256sum -c - \
	&& tar -xzf kong.tar.gz -C /tmp \
	&& rm -f kong.tar.gz \
	&& cp -R /tmp/usr / \
	&& rm -rf /tmp/usr \
	&& cp -R /tmp/etc / \
	&& rm -rf /tmp/etc \
	&& chown -R kong:0 /usr/local/kong \
	&& chmod -R g=u /usr/local/kong

USER kong
COPY --from=build /go/kong-go/*.so  /usr/local/kong/go-plugins/
COPY docker-entrypoint.sh /docker-entrypoint.sh

ENTRYPOINT ["/docker-entrypoint.sh"]

EXPOSE 8000 8443 8001 8444

STOPSIGNAL SIGQUIT

CMD ["kong", "docker-start"]